/**
 * Created by wumian on 17/5/10.
 */
//手机验证
Number.prototype.checkPhone = function () { //直接用5.checkPhone是不行的  5不是Number  要new Number(5).checkPhone
  var phone = this;
  var result = /^1[34578]\d{9}$/.test(phone);
  return result;
};

String.prototype.checkPhone = function () {
  var phone = parseInt(this);
  var result = /^1[34578]\d{9}$/.test(phone);
  return result;
};


//邮箱验证
String.prototype.checkEmail = function () {
  var email = this;
  var result = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email)
  return result;
};

//匹配只含英文和空格和/也就是   匹配英文名
String.prototype.checkEnName = function () {
  var name = this;
  var kk = /^(?=[a-zA-Z\s\/]{6,26}$)/;

  var hh = kk.test(name); //符合true  不符合false

  return hh
};

//匹配中文名字
String.prototype.checkChName = function () {
  var name = this;
  var kk = /^(?=[\u4e00-\u9fa5]{2,11}$)/;

  var hh = kk.test(name); //符合true  不符合false

  return hh
};


//匹配字符串都为中文
String.prototype.checkCh = function () {
  var str = this;
  var kk = /^(?=[\u4e00-\u9fa5]+$)/;
  var hh = kk.test(str); //符合true  不符合false
  return hh
};


//匹配名字 中文或者英文(英文可以用空格/)
String.prototype.checkName = function () {
  var name = this;
  var kk = /^(?=[a-zA-Z\s\/]{2,26}$)/;
  var jj = /^(?=[\u4e00-\u9fa5\s\/]{6,26}$)/;

  if (kk.test(name) || jj.test(name)) {
    return true
  } else {
    return false
  }
};


//飞机名称验证  支持中英文混写,支持空格checkFlightName
String.prototype.checkFlightName = function () {
  var name = this;
  var hh;

  var reg = /^[\u4E00-\u9FA5\a-zA-Z\s\/]+$/; // 匹配全是中文或者英文或者空格和/

  var regChs = /^[\u4E00-\u9FA5\s]+$/;//匹配全是汉子或空格

  var regEn = /^[\a-zA-Z\s\/]/;//匹配是英文字母或者空格

  var regCh = /^[\u4E00-\u9FA5]/;//匹配是单个汉子

  var num = 0;

  if (regChs.test(name)) {//全是中文或空格进行中文名匹配
    if (name.checkChName()) {
      hh = true;
    } else {
      hh = false;
    }

  } else if (reg.test(name)) {
    for (var i = 0; i < name.length; i++) {
      if (regEn.test(name[i])) {
        num++
      }
      if (regCh.test(name[i])) {
        num += 2
      }
    }
    if (num > 26 || num < 6) {
      hh = false
    } else {
      hh = true;
    }

  } else {
    hh = false;
  }
  return hh
};

Date.prototype.format = function (format) {
  var o = {
    "M+": this.getMonth() + 1, //month
    "d+": this.getDate(),    //day
    "h+": this.getHours(),   //hour
    "m+": this.getMinutes(), //minute
    "s+": this.getSeconds(), //second
    "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
    "S": this.getMilliseconds() //millisecond
  }
  if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
    (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)if (new RegExp("(" + k + ")").test(format))
    format = format.replace(RegExp.$1,
      RegExp.$1.length == 1 ? o[k] :
        ("00" + o[k]).substr(("" + o[k]).length));
  return format;
}





